/*
 * Copyright 2014 JooKar (info@jookar.nl)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package nl.jookar.privatechat.bussiness;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import nl.jookar.privatechat.model.Message;
import nl.jookar.privatechat.model.User;

/**
 * A queue of {@link Message} instances waiting to be send
 * 
 * @author Joost A. Bloemsma
 */
public class MessageQueue {
    private User user;
    private List<Message> msgs = new ArrayList<Message>();
    
    /**
     * Constructs a new MessageQueue instance
     * @param user
     */
    public MessageQueue(User user) {
        super();
        this.user = user;
    }
    
    /**
     * Add a {@link Message} to the Message queue
     * @param msg
     */
    public void addMessage(Message msg) {
        msg.setTimeStamp(new Date());
        msgs.add(msg);
    }
    
    /**
     * Pop the first {@link Message} from the queue
     * @return The first {@link Message}
     */
    public Message popMessage() {
        Message msg = null;
        if (msgs.size() > 0) {
            msg = msgs.remove(0);
        }
        return msg;
    }
    
    /**
     * @return the user
     */
    public User getUser() {
        return user;
    }

    /**
     * @param user the user to set
     */
    public void setUser(User user) {
        this.user = user;
    }
    
    
}

